package offer;

/**
 * <p>
 * 剑指 Offer 24. 反转链表
 * </p>
 *
 * @author xiaozuolin
 * @date 2021/9/23 15:11
 */
public class Offer24 {

    public ListNode reverseList(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;
        while (cur != null) {
            ListNode tmp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = tmp;
        }
        return pre;
    }

    public ListNode recur(ListNode cur, ListNode pre) {
        if (cur == null) {
            return pre;
        }
        ListNode res = recur(cur.next, cur);
        cur.next = pre;
        return res;
    }
}
